<!doctype html>
<html class="x-admin-sm">
<#include "../header.ftl">
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">系统管理</a>
            <a><cite>角色管理</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="/SysRole/roleList" title="刷新"> <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" action="/SysRole/roleList?v=search" id="form1">
                        <input id="pageNumber" name="pageNumber" type="hidden" value="1">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="roleName" placeholder="请输入角色名称" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除
                    </button>
                    <button class="layui-btn" onclick="xadmin.open('添加角色','./roleEdit?v=add')"><i
                                class="layui-icon"></i>添加
                    </button>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form" lay-size="sm">
                        <thead>
                        <tr>
                            <th>
                                <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary">
                            </th>
                            <th>ID</th>
                            <th>角色名</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#list page.list as _>
                            <tr>
                                <td>
                                    <input type="checkbox" name="id" value="${_.id}" lay-skin="primary">
                                </td>
                                <td>${_.id}</td>
                                <td>${_.roleName}</td>
                                <td class="td-manage">
                                    <a class="layui-btn layui-btn-sm" title="编辑" onclick="xadmin.open('编辑','member-edit.html',600,400)"
                                       href="javascript:;">编辑 </a>
                                </td>
                            </tr>
                        </#list>
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <#import "../page.ftl" as pageTpl/>
                    <@pageTpl.page pageNo=page.currPage  totalCount=page.totalCount totalPage=page.totalPage showPages=2 callFunName="showPage"/>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use([ 'form'], function () {
        var form = layui.form;
        form.on('submit(search)', function (data) {
            alert(0)
            $("#form1").submit();
        });
        // 监听全选
        form.on('checkbox(checkall)', function (data) {
            if (data.elem.checked) {
                $('tbody input').prop('checked', true);
            } else {
                $('tbody input').prop('checked', false);
            }
            form.render('checkbox');
        });
    });
    function delAll(argument) {
        var ids = [];
        // 获取选中的id
        $('tbody input').each(function (index, el) {
            if ($(this).prop('checked')) {
                ids.push($(this).val())
            }
        });
        layer.confirm('确认要删除吗？' + ids.toString(), function (index) {
            //捉到所有被选中的，发异步进行删除
            $.ajax({
                type: "POST",                      //请求类型
                url: "./roleEdit?v=del&ids="+ids.toString(),                 //URL
                dataType: "json",                 //返回的数据类型
                async: false,//使用同步的方式,true为异步方式
                success: function (data) {          //data就是返回的json类型的数据
                    console.log(data);
                    window.location.reload();
                }
            });
        });
    }
</script>
</html>